<?php
	 /*  error_reporting(E_ALL);
          ini_set("display_errors", 1); */
		  
/* #############################################################################################
   @Modulo Phone Payment 
   # Autor: Walter Hernandez 
   # e-mail: info@goldenfoxi.com 
   # web : wwww.goldenfoxi.com 
   ##################### copyright www.goldenfoxi.com - 2012 - ################################## */ 
   
class PhonePaymentValidationModuleFrontController extends ModuleFrontController
{
	public function postProcess()
	{
		$cart = $this->context->cart;
		if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active)
			Tools::redirect('index.php?controller=order&step=1');
			
		$authorized = false;
		
		foreach (Module::getPaymentModules() as $module)
			if ($module['name'] == 'phonepayment')
			{
				$authorized = true;
				
				break;
			}
			
		if (!$authorized) die($this->module->l('Este medio de pago No esta disponible!', 'validation'));

		$customer = new Customer($cart->id_customer);
		
		if (!Validate::isLoadedObject($customer)) Tools::redirect('index.php?controller=order&step=1');

		$currency = $this->context->currency;
		
		$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
		
		$mailVars = array('{telefono_pp}' => Configuration::get('TELEFONO_PP'),
		                  '{horario_pp}' => Configuration::get('HORARIO_PP'),
						  '{comentario_pp}' => nl2br(Configuration::get('COMENTARIO_PP')));
										

$this->module->validateOrder($cart->id, Configuration::get('PS_OS_PHONEPAYMENT'), $total, $this->module->displayName, NULL, $mailVars, (int)$currency->id, false, $customer->secure_key);
		
		Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
		
	    }
	
   }
   
?>
